
#include "ednn.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <time.h>

#ifdef _WIN32
#include <Windows.h>
#endif



static ednn_size_t ednn_memory_used = 0;

void *ednn_mem_zalloc(ednn_size_t size)
{
    void *p = malloc(size);
    if (p) {
        memset(p, 0x0, size);
        ednn_memory_used += size;
    }

    return p;
}

void ednn_mem_free(void *p)
{
    free(p);
}

ednn_size_t ednn_mem_used(void)
{
    return ednn_memory_used;
}

#ifdef _WIN32
ednn_uint32_t ednn_ms_get(void)
{
    ednn_uint32_t ms;
    time_t t1;
    SYSTEMTIME t2;
    
    time(&t1);
    GetSystemTime(&t2);
    ms = (ednn_uint32_t)(t1*1000 + t2.wMilliseconds);

    return ms;
}

ednn_uint64_t ednn_us_get(void)
{
    double dt;
    LARGE_INTEGER freq, t;

    QueryPerformanceFrequency(&freq);
    QueryPerformanceCounter(&t);

    dt = t.QuadPart/(double)freq.QuadPart;

    return (ednn_uint64_t)(dt*1000000);
}
#endif